package com.tlcx.kfip.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tlcx.kfip.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 选择支付方式view
 * Created by victor on 2016/11/21 10:52.
 * Email:zhuzhaoyang@yuanchuangyun.com
 */

public class SelectPaymentWayView extends LinearLayout {

    private Context mContext;

    @BindView(R.id.rl_payment_wechat)           RelativeLayout wechatLayout;
    @BindView(R.id.rl_payment_alipay)           RelativeLayout alipayLayout;
    @BindView(R.id.tv_pay_way_wx_instruction)   TextView wxInstructionTv;
    @BindView(R.id.tv_pay_way_instruction)      TextView alipayInstructionTv;
    @BindView(R.id.cb_payment_alipay)           CheckBox alipayCb;
    @BindView(R.id.cb_payment_wechat)           CheckBox wechatCb;

    public SelectPaymentWayView(Context context) {
        super(context);
        initView(context);
    }

    public SelectPaymentWayView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public SelectPaymentWayView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    /**
     * 初始化view
     */
    private void initView(Context context){
        mContext = context;
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = mInflater.inflate(R.layout.widget_select_payment_way,null,false);
        addView(view);
        ButterKnife.bind(this,view);
    }

    /**
     * 点击选择支付宝支付
     */
    @OnClick(R.id.rl_payment_alipay)
    public void clickAliPay(){
       if (!alipayCb.isChecked()){
           alipayCb.setChecked(true);
           wechatCb.setChecked(false);
           alipayInstructionTv.setTextColor(getResources().getColor(R.color.recharge_payment_type_text_color_selected));
           wxInstructionTv.setTextColor(getResources().getColor(R.color.recharge_payment_type_text_color_normal));
       }
    }

    /**
     * 点击选择微信支付
     */
    @OnClick(R.id.rl_payment_wechat)
    public void clickWechat(){
        if (!wechatCb.isChecked()){
            wechatCb.setChecked(true);
            alipayCb.setChecked(false);
            wxInstructionTv.setTextColor(getResources().getColor(R.color.recharge_payment_type_text_color_selected));
            alipayInstructionTv.setTextColor(getResources().getColor(R.color.recharge_payment_type_text_color_normal));
        }
    }

    /**
     * 获得返回结果  0：表示选择的是微信支付；1：表示选择的是支付宝支付
     * @return
     */
    public int getSelectedResult(){
        if (wechatCb.isChecked())
            return 0;
        if (alipayCb.isChecked())
            return 1;
        return 0;
    }
}
